#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tornado.web import RequestHandler
import pymongo
import re
import render
import codecs
import csv
from _base import BaseHandler
import datetime
import sys
sys.path.insert(0,'/home/leeray/workspaces/Python/wanalytics/')
sys.path.insert(0,'/opt/web/')
from Tools import getPid
from Tools import connectMySQL 
import json
from util import cache, settings
import _clientCache as clientcache
import logging


class GetCsvs(BaseHandler):    
    
    def post(self):        
	    _data = self.get_argument("csv_text")
	    self.set_header("Content-Type", "text/csv;charset=UTF-8")
	    self.set_header("Content-Disposition", "attachment;filename=Report.csv;charset=UTF-8")
	    _data = _data.encode('gb2312','ignore') 
	    self.write(_data)
    
    def get(self):        
	    _data = self.get_argument("csv_text","\"20120619\",\" 6,731 1,141\" \"20120619\",\" 6,731 1,141\"")
	    self.set_header("Content-Type", "text/csv;charset=UTF-8")
	    self.set_header("Content-Disposition", "attachment;filename=Report.csv;charset=UTF-8")
	    _data = _data.encode('gb2312','ignore') 
	    self.write(_data)
        
class GetCsvssave(BaseHandler):    
    
    def post(self):        
        _data = self.get_argument("csv_text","null").strip()
        _uid = self.get_argument("uid")
        if _data == "null":
            self.write("ok")
        else:
            _data = _data.encode('gb2312','ignore')
            #f = open("/opt/web/Statis/web/ykAnalytics/Report_%s.csv" % _uid ,"w") 
            f = open("/home/liuyue/Ubuntu One/wan/Statis/web/ykAnalytics/Report_%s.csv" % _uid ,"w")
            f.write(_data)
            f.close()
            self.write(_data)
        
        
        
                
class Test(BaseHandler):    
    
    def get(self):        
	    
        self.write("123")






